define(function (require, exports, module) {
    var ieShim = require('ie/ie-shim.js');
    ieShim.init();

    var page = require("page");
    var $ = require("jquery");
    require("bootstrap")($);
    require("modernizr");
    var Handlebars = require("Handlebars");
    require('cookie');
    
    if (!window.i18n) {

        var i18nx = require("i18next");
        i18nx.init({
            lng: $.cookie("i18next") || "zh-CN",
            fallbackLng: false,
            load: 'current'
        }, function (t) {
            LoadContent();
        });
        window.i18n = i18nx;
    } else {
        LoadContent();
    }
    window.module_util = require('./module_utils.js');
    function LoadContent(){
        //auto login
        var appId = $.cookie('curAppId');
        var userIcon = $.cookie('userIcon');
        $.ajax({
            url: 'ajax.php',
            type: 'GET',
            dataType: 'json',
            cache: false
        })
        .done(function(data) {
            if (data && data.status == 1) {
                //是否为开发者
                $.cookie('isDeveloper', data.result.verifyState);

                $('.link-group').addClass('active');
                $('#ifSigned').addClass('active');
                $('#ifSigned img').attr('src', data.result.icon2 || '/img/favicon-30.png');
                var txt = data.result.userName;
                $('#ifSigned .toConsole span').eq(0).text(txt);
            } else{
                $('.link-group').removeClass('active');
                $('#ifSigned').removeClass('active');
                $('#ifSigned img').attr('src', '');
                $('#ifSigned .toConsole span').eq(0).text('');
            }
        });
        
        var utils = require('./utils.js');
        //切换语言
        var lang = $.cookie('i18next');
        if(lang=="en-US"){
            $(".hidebox .langbox").removeClass("selected");
            var enlish=$(".hidebox .langbox").eq(1);
            $("#selectLang").html(enlish.html());
            enlish.addClass("selected");
        }
        $("#selectLang").on("click",function(){
            $(".hidebox").show();
        });
        $(".hidebox").find(".langbox").on("click",function(){
            i18n.setLng($(this).attr("lang"));
            location.reload();
        });
        $(document.body).on("click", function (e) {
            var target = $(e.target);
            if ($(".hidebox").get(0)) {
                if (!$.contains($(".hidebox").get(0), e.target)
                    && !$.contains($("#selectLang").get(0), e.target)
                    && (!target.is('.hidebox'))
                    && (!target.is('#selectLang'))) {
                    $(".hidebox").hide();
                }
            }
        })


        //for IE
        if(utils.ltIE10()){
            require.async('ie/ie.js', function(mod){
                mod.init();
            });
        }
        //退出登录
        $('#sign_out').one('click', function () {
            $.removeCookie('curAppId');
            $.removeCookie('curAppName');
            $.removeCookie('username');
            $.removeCookie('nickname');
            $.removeCookie('ul_token');
            //BBS login
            $.ajax({
                url: '/api/user/signout',
                type: 'GET',
                cache: false,
                async: false
            }).done(function (data) {
                if (data && data.status == 1) {
                    var bbsFrm = $('#bbsLogin')[0].contentWindow.document.getElementById('bbsFrm3');
                    bbsFrm.submit();
                    setTimeout(function () {
                        location.href = 'login.html';
                    }, 2000);
                }
            });

            return false;
        });

        //load page exec script
        var pathname = location.pathname;
        var fun = pathname.slice(1);
        fun = fun || 'index';
        require.async("dev/"+ fun,function(module){
            module.init();
        });
    }

});